<template>
  <div class="workflow_input">
    <div class="workflow_input_title" v-show="!hideTitle">{{field ? field.alia : ''}}</div>
    <div class="workflow_input_container">
      <!-- <input class="workflow_input_input" v-show="!selectData" :value="value" @input="input"/>
      <input class="workflow_input_input" v-show="selectData" @input="input"/>
      <div class="workflow_input_select" v-if="selectData">{{selectData.alia}}</div> -->
      <workflow-input-custom v-model="text" @html_data="html_data" :pinjie_str="pinjie_str" :data_obj_old="data_obj" :webhook="webhook"></workflow-input-custom>
      <button-popover :output="output" @change="handleSelectChange"></button-popover>
    </div>
  </div>
</template>

<script>
import ButtonPopover from './buttonPopover.vue'
import workflowInputCustom from './workflowInputCustom.vue'
export default {
	props: {
		value: {
			default: ""
		},
    field: Object,
    hideTitle: Boolean,
		output: {
			default: []
		},
    data_obj: {
      type: Object,
      default: {}
    },
    webhook: {
      default: ''
    },
    formStoreData: {
      type: Object,
      default: {}
    },
    field_name: ''
	},
  components:{
    ButtonPopover,
    workflowInputCustom
  },
	data(){
		return{
      selectData: null,
      text: {} || '',
      pinjie_str: ''
		}
	},
	methods:{
    html_data(text, data, data_obj) {
			this.$emit('change', text, data, data_obj, this.field_name);
      this.$emit('input', data);
    },
		// input(event){
    //   this.selectData = null
		// 	this.$emit('input',event.target.value);
		// 	this.$emit('change',event.target.value);
		// },
    handleSelectChange(data){
      this.text = data
      this.pinjie_str = `{{${data.parentNodeId}.outputs.${data.parentKey}.${data.name}}}`
      // this.selectData = data
			// this.$emit('input', `{{${data.parentNodeId}.outputs.${data.parentKey}.${data.name}}}`);
			// this.$emit('change', `{{${data.parentNodeId}.outputs.${data.parentKey}.${data.name}}}`);
      // this.value = ''
    },
    // findSelectItem(str){
    //   let split = str.split('.')
    //   for (let i = 0; i < this.output.length; i++) {
    //     if(this.output[i].nodeId === split[0]){
    //       // this.selectData = this.output[i].outputs.find(c => c.name === split[split.length - 1])
    //       this.text = this.output[i].outputs.find(c => c.name === split[split.length - 1])
    //     }
    //   }
    // }
	},
  mounted(){
    // let re = /^{{(\w+(?:\.\w+)+)}}$/
    // if(re.test(this.value)){
    //   this.findSelectItem(re.exec(this.value)[1])
    // }
    if(this.formStoreData[this.field_name]){
      this.text = this.formStoreData[this.field_name]?.noticeStoreData || ''
    }else{
      this.text = this.value
    }
  },
  computed:{
  }
}

</script>

<style lang="less">
.workflow_input{
    // display: flex;
    // align-items: center;
    .workflow_input_title{
      margin-bottom: 5px;
      margin-top: 5px;
    }

    .workflow_input_container{
      display: flex;
      align-items: center;
      position: relative;

      .workflow_input_input{
        background-color: #fff;
        background-image: none;
        border: 1px solid #d9d9d9;
        border-radius: 4px;
        flex: 1 1 auto;
        color: rgba(0, 0, 0, 0.65);
        overflow: hidden;
        text-overflow: ellipsis;
        height: 32px;
        padding: 0 10px;
      }

      .workflow_input_select{
        margin: 0 10px;
        padding: 0 10px;
        position: absolute;
        background-color: rgba(127, 255, 212, 0.6);
      }
    }
}
</style>